//
//  LYFestivalView.m
//  SZBank
//
//  Created by LuoYao on 16/7/12.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "LYFestivalView.h"

@interface LYFestivalView ()
{
    NSMutableArray *_topImageNames;/**< 图片数组 */
}
@property (nonatomic) UIScrollView *scrollview;/**< 图片滑动 */
@property (nonatomic) UIImageView *topImageView;/**< 顶部图片 */
@end
@implementation LYFestivalView

- (instancetype)initWithFrame:(CGRect)frame topImageNames:(NSArray *)topImageNames
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _topImageNames = [NSMutableArray array];

        
        //处理无效链接
        for (NSDictionary *dic in topImageNames) {
            if ([dic[@"ORDER"] integerValue] != 10) {
                [_topImageNames addObject:dic];
            }
            
        }
        
        
        //背景
        self.backImageView.image = [LocalDataManager getImageWithSourceOfPath:@"小背景"];
        
        //上边显示图片
        self.topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _cKwidth * 0.6, _cKheight * 0.6)];
        self.topImageView.center = CGPointMake(self.center.x, _cKheight * 0.35);
        //图片默认值
        self.topImageView.image = [LocalDataManager getImageWithURL:_topImageNames[0][@"DETAILSURL"]];
        
        [self addSubview:self.topImageView];
        
        
        //滑动图片
        for (int i = 0; i < _topImageNames.count; i ++) {
            UIButton *image = [[UIButton alloc] initWithFrame:CGRectMake(i * _cKwidth * 0.20, _cKheight * 0.05, _cKwidth * 0.16, _cKheight * 0.18)];
            [image setBackgroundImage:[LocalDataManager getImageWithURL:_topImageNames[i][@"THUMBNAILURL"]] forState:UIControlStateNormal];
            image.tag = 1000 + i;
            [image addTarget:self action:@selector(action_btnClick:) forControlEvents:UIControlEventTouchUpInside];
            
            [self.scrollview addSubview:image];
        }
        
        
        [self addSubview:self.scrollview];
        
        
        //底部阴影
        UIImageView *bottomImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _cKheight * 0.95, _cKwidth, _cKheight * 0.05)];
        bottomImageView.image = [LocalDataManager getImageWithSourceOfPath:@"金融资讯_底边"];
        
        [self addSubview:bottomImageView];
        
        
        
    }
    return self;
}


#pragma mark - 点击事件
- (void)action_btnClick:(UIButton *)sender{
    //图片赋值
    self.topImageView.image = [LocalDataManager getImageWithURL:_topImageNames[sender.tag - 1000][@"DETAILSURL"]];
}

#pragma mark - getter
- (UIScrollView *)scrollview{
    if (!_scrollview) {
        _scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _cKheight * 0.7, _cKwidth, _cKheight * 0.25)];
        _scrollview.contentSize = CGSizeMake((_cKwidth * 0.20) * _topImageNames.count, _cKheight * 0.25);
        _scrollview.showsHorizontalScrollIndicator = NO;
        
    }
    return _scrollview;
}

@end
